package com.xxxx.server.common.utils;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Locale;

/**
 * 日期转换工具类
 */
@Component
public class DateUtils implements Converter<String, LocalDate> {
    @Override
    public LocalDate convert(String source) {
        if (source != null && source != "") {
            try {
                // 转换日期格式
                return LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd").withLocale(Locale.CHINA));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
